import {IAnswer} from "@/model/answer";
import { ICheck } from "@/model/check";
import {IQuestion} from "@/model/question";

export interface IChecker {
  check(ans: IAnswer, question: IQuestion):ICheck;
}

export class GussBigChecker implements  IChecker {
  check(ans: IAnswer, question: IQuestion): ICheck {
    const _out: ICheck = {
      isSuccess: false,
      msg:""
    }

    let a = Number(ans.answer);
    let q = Number(question.question);
    if (a === q){
      _out.isSuccess = true;
      _out.msg = "答对了！"
    }else if (a < q) {
      _out.msg = "小了！"
    }else {
      _out.msg = "大了！"
    }

    return _out
  }
}

export class GussLowChecker implements  IChecker {
  check(ans: IAnswer, question: IQuestion): ICheck {
    const _out: ICheck = {
      isSuccess: false,
      msg:""
    }

    let a = Number(ans.answer);
    let q = Number(question.question);
    if (a === q){
      _out.msg = "还差一点点"
    }else if (a < q) {
      _out.isSuccess = true;
      _out.msg = "答对了！"
    }else {
      _out.msg = "大了！"
    }

    return _out
  }
}

export class GussNumChecker implements  IChecker {
  check(ans: IAnswer, question: IQuestion): ICheck {
    const _out: ICheck = {
      isSuccess: false,
      msg:""
    }

    let a = 0
    let b = 0

    for (let i = 0; i < ans.answer.length; i++) {
      const _index = question.question.indexOf(ans.answer[i])
      if (_index !== -1){
        if(_index === i){
          a+=1
        }else {
          b+=1
        }
      }
    }

    if(a === 4){
      _out.isSuccess = true
    }
    _out.msg = `${a}A${b}B`

    return _out
  }
}